package com.atguigu.gmall.realtime.common.function;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.PropertyNamingStrategy;
import com.alibaba.fastjson.serializer.SerializeConfig;
import org.apache.flink.api.common.functions.MapFunction;

/**
 * ClassName: BeanToJsonStrMapFunction
 * Description:
 * 将实体类对象转换为json字符串
 * @Create 2024/4/25 11:20
 */
public class BeanToJsonStrMapFunction<T> implements MapFunction<T, String> {
    @Override
    public String map(T bean) throws Exception {

        SerializeConfig config = new SerializeConfig();
        //驼峰转为蛇形
        config.setPropertyNamingStrategy(PropertyNamingStrategy.SnakeCase);

        String jsonStr = JSON.toJSONString(bean, config);

        return jsonStr;
    }
}
